package com.googlecode.lookie.platform.flexdock;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.flexdock.perspective.LayoutSequence;
import org.flexdock.perspective.Perspective;
import org.flexdock.perspective.PerspectiveFactory;

public class PlatformPerspectiveFactory
    implements PerspectiveFactory
{

    private Map<String, PerspectiveContribution> map;

    List<PerspectiveContribution> perspectives;

    public void setPerspectives( List<PerspectiveContribution> perspectives )
    {
        this.perspectives = perspectives;
    }

    protected Map<String, PerspectiveContribution> getPerspectives()
    {
        if (map == null) {
            map = new HashMap<String, PerspectiveContribution>();
            for (PerspectiveContribution perspective : perspectives) {
                    map.put( perspective.getId(), perspective );
            }

            map.put( "welcome",  new WelcomePerspective());
        }
        return map;
    }

    public Perspective getPerspective( String persistentId )
    {
        PerspectiveContribution pluginPerspective = getPerspectives().get( persistentId );

        if (pluginPerspective != null) {
            Perspective perspective = new Perspective( persistentId, pluginPerspective.getName() );
            LayoutSequence sequence = perspective.getInitialSequence( true );
            pluginPerspective.configure( sequence );
            return perspective;

        }

        return null;
    }

}
